//
//  AppDelegate.m
//  WayToHome
//
//  Created by A-01 on 2020/6/22.
//  Copyright © 2020 A-01. All rights reserved.
//

#import "AppDelegate.h"
#import "ViewController.h"

@interface AppDelegate ()<AVAudioPlayerDelegate>

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    [NSThread sleepForTimeInterval:1];
    
    if (@available(iOS 13.0, *)) {
    
    } else {
          
        self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
          
        self.window.rootViewController = [[UINavigationController alloc] initWithRootViewController:[ViewController new]];
          
        [self.window makeKeyAndVisible];
    }
    
    [self setBackgroundMusic];
    return YES;
}

- (void)setBackgroundMusic{
    NSString *path = [[NSBundle mainBundle] pathForResource:@"bgm" ofType:@"mp3"];
    NSURL *url = [[NSURL alloc] initFileURLWithPath:path];
    self.audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:nil];
    self.audioPlayer.volume = 1;
    self.audioPlayer.delegate = self;
    
    [self.audioPlayer play];
}

// 播放器代理 播放完成的时候再次播放
- (void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag{
    [self.audioPlayer play];
}

-(void)pluaseMusic{
    
    [self.audioPlayer pause];
}
-(void)playMusic{
    
    [self.audioPlayer play];
}

#pragma mark - UISceneSession lifecycle


- (UISceneConfiguration *)application:(UIApplication *)application configurationForConnectingSceneSession:(UISceneSession *)connectingSceneSession options:(UISceneConnectionOptions *)options  API_AVAILABLE(ios(13.0)){
    // Called when a new scene session is being created.
    // Use this method to select a configuration to create the new scene with.
    return [[UISceneConfiguration alloc] initWithName:@"Default Configuration" sessionRole:connectingSceneSession.role];
}


- (void)application:(UIApplication *)application didDiscardSceneSessions:(NSSet<UISceneSession *> *)sceneSessions  API_AVAILABLE(ios(13.0)){
    // Called when the user discards a scene session.
    // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
    // Use this method to release any resources that were specific to the discarded scenes, as they will not return.
}


@end
